{extends file='dashboard.tpl'}
{block name='body'}
{block name='menus'}{$smarty.block.parent}{/block}
<h2>Semua Transaksi</h2>
{block name='pilih_tahun'}
<label>
    <span>Pilih Tahun:</span>
    <select id="tahun">
        <option value=""></option>
        {foreach $tahun as $t}
        <option value="{$t.link}" {if $t.tahun==$tahun_selected} selected="selected"{/if}>{$t.tahun}</option>
        {/foreach}
    </select>
</label>
{literal}
<script type="text/javascript">
(function($){
    $('#tahun').change(function(e){
        var link = $(e.target).val();

        if(link.length > 0) window.location = link;
    });
})(jQuery);
</script>
{/literal}
{/block}

{block name='toolbar'}
<div class="toolbar"><button id="add-transaction">Tambah</button></div>
{/block}

{if isset($transactions)}
{if count($transactions) > 0}
<table id="transaction-table" class="tablesorter">
    <thead>
    {foreach $fields as $f}
    <th>{$f@key}</th>
    {/foreach}
    </thead>
</table>
{literal}
<script type="text/javascript">
(function($){
    $('#transaction-table').tablesorter();
})(jQuery);
</script>
{/literal}
{else}
<h3>Belum ada transaksi</h3>
{/if}
{/if}

<div id="box-tambah-transaksi" title="Box Transaksi">
    <form id="form-tambah-transaksi" action="{site_url('quotes_and_sales/all_transaction/add')}">
        <label>
            <span>Jenis Transaksi:</span>
            <select name="kode">
                {foreach $kode_transaksi as $kode}
                <option value="{$kode}">{strtoupper(str_replace('_', ' ', $kode@key))}</option>
                {/foreach}
            </select>
        </label>
        <input type="hidden" name="tahun" value="{$tahun_selected}" />
    </form>
</div>
{literal}
<script type="text/javascript">
(function($){
    $('#box-tambah-transaksi').dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            "Tambah": function(){
                $('#form-tambah-transaksi').submit();
            }
        }
    });
    $('#add-transaction').click(function(){
        $('#box-tambah-transaksi').dialog('open');
    });
})(jQuery);
</script>
{/literal}
{/block}